package cn.jeeweb.web.modules.oss.controller;

import cn.jeeweb.common.http.Response;
import cn.jeeweb.common.http.ResponseCode;
import cn.jeeweb.common.mvc.controller.BaseController;
import cn.jeeweb.common.mybatis.mvc.wrapper.EntityWrapper;
import cn.jeeweb.common.oss.config.OssConfig;
import cn.jeeweb.common.oss.exception.FileNameLengthLimitExceededException;
import cn.jeeweb.common.oss.exception.InvalidExtensionException;
import cn.jeeweb.common.utils.*;
import cn.jeeweb.web.modules.equipment.entity.EqsEquipment;
import cn.jeeweb.web.modules.equipment.entity.EqsEquipmentFixture;
import cn.jeeweb.web.modules.equipment.entity.EqsSparePart;
import cn.jeeweb.web.modules.equipment.service.IEqsEquipmentFixtureService;
import cn.jeeweb.web.modules.equipment.service.IEqsEquipmentService;
import cn.jeeweb.web.modules.equipment.service.IEqsSparePartService;
import cn.jeeweb.web.modules.oss.entity.Attachment;
import cn.jeeweb.web.modules.oss.helper.AttachmentHelper;
import cn.jeeweb.web.modules.oss.service.IAttachmentService;
import cn.jeeweb.web.modules.sys.entity.User;
import cn.jeeweb.web.utils.UserUtils;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.apache.commons.fileupload.FileUploadBase;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Controller;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.HandlerMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLDecoder;
import java.sql.Timestamp;
import java.util.*;

/**
 * @title: 附件管理控制器
 * @description: 附件管理控制器
 */

@RestController
@RequestMapping("oss")
public class OSSUploadController extends BaseController {

    @Autowired
    private AttachmentHelper attachmentHelper;

    @Autowired
    private IAttachmentService attachmentService;

    @Autowired
    private OssConfig ossConfig;

    @Autowired
    private IEqsEquipmentService eqsEquipmentService;

    @Autowired
    private IEqsSparePartService eqsSparePartService;

    @Autowired
    private IEqsEquipmentFixtureService eqsEquipmentFixtureService;


//    @Value("${oss.local.upload-file-path}")
//    private String uploadPath;

    /**
     * @param request
     * @param response
     * @return
     * @title: ajaxUpload
     * @description: 文件上传
     * @return: AjaxUploadResponse
     */
    @RequestMapping(value = "upload", method = {RequestMethod.POST, RequestMethod.GET})
    public Response upload(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/plain");
        Response responseResult = new Response();
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
                request.getServletContext());
        List<Attachment> attachmentList = new ArrayList<Attachment>();
        if (multipartResolver.isMultipart(request)) { // 判断request是否有文件上传
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
            Iterator<String> ite = multiRequest.getFileNames();
            while (ite.hasNext()) {
                MultipartFile file = multiRequest.getFile(ite.next());
                try {
                    Attachment attachment = attachmentHelper.upload(request, file);
                    attachmentList.add(attachment);
                    continue;
                } catch (IOException e) {
                    return Response.response(ResponseCode.NORMAL_ERROR, MessageUtils.getMessage("upload.server.error"));
                } catch (InvalidExtensionException e) {
                    return Response.response(ResponseCode.NORMAL_ERROR, MessageUtils.getMessage("upload.server.error"));
                } catch (FileUploadBase.FileSizeLimitExceededException e) {
                    return Response.response(ResponseCode.NORMAL_ERROR, MessageUtils.getMessage("upload.server.error"));
                } catch (FileNameLengthLimitExceededException e) {
                    return Response.response(ResponseCode.NORMAL_ERROR, MessageUtils.getMessage("upload.server.error"));
                }
            }
            responseResult.put("attachment_list", attachmentList);
        }
        return responseResult;
    }


    /**
     * 多文件上传
     *
     * @param request
     * @param response
     * @return
     * @title: ajaxUpload
     * @description: 文件上传
     * @return: AjaxUploadResponse
     */
    @RequestMapping(value = "multiUpload", method = {RequestMethod.POST, RequestMethod.GET})
    public Response multiUpload(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/plain");
        Response responseResult = new Response();
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
                request.getServletContext());
        List<Attachment> attachmentList = new ArrayList<Attachment>();
        if (multipartResolver.isMultipart(request)) { // 判断request是否有文件上传
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
            List<MultipartFile> fileList = multiRequest.getFiles("file");
            if (fileList != null && fileList.size() > 0) {
                for (MultipartFile multipartFile : fileList) {
                    Attachment attachment = null;
                    try {
                        attachment = attachmentHelper.upload(request, multipartFile);
                    } catch (FileUploadBase.FileSizeLimitExceededException e) {
                        e.printStackTrace();
                    } catch (FileNameLengthLimitExceededException e) {
                        e.printStackTrace();
                    } catch (InvalidExtensionException e) {
                        e.printStackTrace();
                    }
                    attachmentList.add(attachment);
                }
            }
            responseResult.put("attachment_list", attachmentList);
        }
        return responseResult;
    }

    /**
     * @param request
     * @param response
     * @return
     * @title: ajaxUpload
     * @description: 文件上传
     * @return: AjaxUploadResponse
     */
    @RequestMapping(value = "uploadSimditor", method = RequestMethod.POST)
    public Response uploadSimditor(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("text/plain");
        Response responseData = Response.ok();
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
                request.getServletContext());
        List<Attachment> attachmentList = new ArrayList<Attachment>();
        if (multipartResolver.isMultipart(request)) { // 判断request是否有文件上传
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
            Iterator<String> ite = multiRequest.getFileNames();
            while (ite.hasNext()) {
                MultipartFile file = multiRequest.getFile(ite.next());
                try {
                    Attachment attachment = attachmentHelper.upload(request, file);
                    attachmentList.add(attachment);
                } catch (IOException e) {
                    Response.error(MessageUtils.getMessage("upload.server.error"));
                } catch (InvalidExtensionException e) {
                    Response.error(MessageUtils.getMessage("upload.server.error"));
                } catch (FileUploadBase.FileSizeLimitExceededException e) {
                    Response.error(MessageUtils.getMessage("upload.server.error"));
                } catch (FileNameLengthLimitExceededException e) {
                    Response.error(MessageUtils.getMessage("upload.server.error"));
                }
            }
            String ctxPath = request.getContextPath();
            responseData.putList("attachmentList", attachmentList);
            responseData.put("success", Boolean.TRUE);
            responseData.put("msg", MessageUtils.getMessage("upload.server.error"));
            responseData.put("file_path", ctxPath + "/" + attachmentList.get(0).getFilePath());
        } else {
            responseData.put("success", Boolean.FALSE);
            responseData.put("msg", MessageUtils.getMessage("upload.server.error"));
        }
        return responseData;
    }

    @RequestMapping(value = "test", method = RequestMethod.GET)
    public void test() {
        System.out.println("run");
    }

    /**
     * type参数：0：代表查看，1：代表下载
     *
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping(value = "getImage/**")
    public void getImage(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // ISO-8859-1 ==> UTF-8 进行编码转换
        String filename = extractPathFromPattern(request);
        String baseDir = ossConfig.getLocal().getUploadFilePath();
        String type = request.getParameter("type");
        String fileName_ = baseDir + "/" + filename;
//        FileUtil.downloadJpeg(response,fileName_);
        FileUtil.downloadFile(response, fileName_, type);
    }


    // 把指定URL后的字符串全部截断当成参数
    // 这么做是为了防止URL中包含中文或者特殊字符（/等）时，匹配不了的问题
    private static String extractPathFromPattern(final HttpServletRequest request) {
        String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
        String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
        return new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path);
    }

    /**
     * @param request
     * @param response
     * @return
     * @title: ajaxUpload
     * @description: 解析设备excel
     * @return: AjaxUploadResponse
     */
    @RequestMapping(value = "importEqsEquipmentExcel", method = {RequestMethod.POST, RequestMethod.GET})
    public Response importEecel(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/plain");
        Response responseResult = new Response();
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
                request.getServletContext());
        List<Attachment> attachmentList = new ArrayList<Attachment>();
        if (multipartResolver.isMultipart(request)) { // 判断request是否有文件上传
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
            Iterator<String> ite = multiRequest.getFileNames();
            while (ite.hasNext()) {
                MultipartFile file = multiRequest.getFile(ite.next());
                String result = "";
                Workbook workbook = null;
                EqsEquipment eqsEquipment = null;
                InputStream in = file.getInputStream();
                try {
                    workbook = Workbook.getWorkbook(in);
                } catch (BiffException e) {

                }
                List<EqsEquipment> eqsEquipments = new ArrayList<EqsEquipment>();
                Sheet sheet = workbook.getSheet(0);// 选取excel中的第一页
                int rows = sheet.getRows();// 得到此页的行(不要设置状态列的上传否则管理混乱)
                int cols = sheet.getColumns();// 得到此页的列(以实际设定的列数为准)
                for (int row = 1; row < rows; row++) {
                    String val1 = sheet.getCell(0, row).getContents();//编码
                    String val2 = sheet.getCell(1, row).getContents();//设备名称
                    String val3 = sheet.getCell(2, row).getContents();//财务编号
                    String val4 = sheet.getCell(3, row).getContents();//品牌
                    String val5 = sheet.getCell(4, row).getContents();//规格型号
                    String val6 = sheet.getCell(5, row).getContents();//生产商
                    String val7 = sheet.getCell(6, row).getContents();//供应商
                    String val8 = sheet.getCell(7, row).getContents();//生产日期
                    String val9 = sheet.getCell(8, row).getContents();//价格
                    String val10 = sheet.getCell(9, row).getContents();//合同号
                    String val11 = sheet.getCell(10, row).getContents();//用途
                    if (val1.equals("") && val2.equals("") && val3.equals("") && val4.equals("") && val5.equals("") && val6.equals("") && val7.equals("") && val8.equals("") && val9.equals("") && val10.equals("") && val11.equals("")) {
                        rows = rows - 1;
                    }
                }
                if (rows > 1 && cols == 11) {
                    //导入成功条数
                    int successCount = 0;
                    //导入失败条数
                    int errorCount = 0;
                    for (int j = 1; j < rows; j++) {
                        eqsEquipment = new EqsEquipment();
                        for (int i = 0; i < cols; i++) {
                            String content = sheet.getCell(i, j).getContents();
                            if(i == 0){
                                eqsEquipment.setCode(content);
                            }else if(i == 1){
                                eqsEquipment.setName(content);
                            }else if(i == 2){
                                eqsEquipment.setSecCode(content);
                            }else if(i == 3){
                                eqsEquipment.setBrand(content);
                            }else if(i == 4){
                                eqsEquipment.setModel(content);
                            }else if(i == 5){
                                eqsEquipment.setFac(content);
                            }else if(i == 6){
                                eqsEquipment.setAcc(content);
                            }else if(i == 7){
                                eqsEquipment.setDevDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                            }else if(i == 8){
                                eqsEquipment.setPrice(new Double(content));
                            }else if(i == 9){
                                eqsEquipment.setBuyContract(content);
                            }else if(i == 10){
                                eqsEquipment.setDevUse(content);
                            }else{

                            }
                        }
                        eqsEquipments.add(eqsEquipment);
                    }
                    workbook.close();

                } else {

                }

                if(eqsEquipments.size() > 0){
                    for(EqsEquipment equipment : eqsEquipments){
                        eqsEquipmentService.insert(equipment);
                    }
                }

            }
        }
        return responseResult.ok("操作完成");
    }


    @RequestMapping(value = "importEquipmentExcel", method = {RequestMethod.POST, RequestMethod.GET})
    public Response importEquipmentEecel(MultipartFile file,HttpServletRequest request, HttpServletResponse response) throws IOException {
        Response responseResult = new Response();
        Workbook workbook = null;
        EqsEquipment eqsEquipment = null;
        InputStream in = file.getInputStream();
        try {
            workbook = Workbook.getWorkbook(in);
        } catch (BiffException e) {

        }
        List<EqsEquipment> eqsEquipments = new ArrayList<EqsEquipment>();
        Sheet sheet = workbook.getSheet(0);// 选取excel中的第一页
        int rows = sheet.getRows();// 得到此页的行(不要设置状态列的上传否则管理混乱)
        int cols = sheet.getColumns();// 得到此页的列(以实际设定的列数为准)
        for (int row = 1; row < rows; row++) {
            String val1 = sheet.getCell(0, row).getContents();//编码
            String val2 = sheet.getCell(1, row).getContents();//设备名称
            if (val1.equals("") && val2.equals("")) {
                rows = rows - 1;
            }
        }

        if (rows > 1 && cols == 35) {
            dump:
            for (int j = 2; j < rows; j++) {
                eqsEquipment = new EqsEquipment();
                for (int i = 0; i < cols; i++) {
                    String content = sheet.getCell(i, j).getContents();
                    if(i == 0){
                        //如果资产编码为空忽略这一行。
                        if(StringUtils.isEmpty(content)){
                            break dump;
                        }
                        eqsEquipment.setCode(content);
                    }else if(i == 1){
                        eqsEquipment.setName(content);
                    }else if(i == 2){
                        eqsEquipment.setSecCode(content);
                    }else if(i == 3){
                        eqsEquipment.setKindCode(content);
                    }else if(i == 4){
                        eqsEquipment.setBrand(content);
                    }else if(i == 5){
                        eqsEquipment.setModel(content);
                    }else if(i == 6){
                        eqsEquipment.setOtherProp(content);
                    }else if(i == 7){
                        eqsEquipment.setFac(content);
                    }else if(i == 8){
                        eqsEquipment.setAcc(content);
                    }else if(i == 9){
                        if(!StringUtils.isEmpty(content)){
                            eqsEquipment.setStockDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 10){
                        if(!StringUtils.isEmpty(content)){
                            eqsEquipment.setDevDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 11){
                        if(!StringUtils.isEmpty(content)){
                            eqsEquipment.setPrice(new Double(content));
                        }
                    }else if(i == 12){
                        eqsEquipment.setChargeby(content);
                    }else if(i == 13){
                        eqsEquipment.setDevUseman(content);
                    }else if(i == 14){
                        if(!StringUtils.isEmpty(content)){
                            eqsEquipment.setArDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 15){
                        eqsEquipment.setBuyContract(content);
                    }else if(i == 16){
                        eqsEquipment.setBuyPrs(content);
                    }else if(i == 17){
                        eqsEquipment.setLocationCode(content);
                    }else if(i == 18){
                        eqsEquipment.setDevUse(content);
                    }else if(i == 19){
                        eqsEquipment.setDevSource(content);
                    }else if(i == 20){
                        eqsEquipment.setTotalfee(content);
                    }else if(i == 21){
                        eqsEquipment.setDepreType(content);
                    }else if(i == 22){
                        eqsEquipment.setSalvageValueRate(content);
                    }else if(i == 23){
                        eqsEquipment.setPreDepreciationMoon(content);
                    }else if(i == 24){
                        if(!StringUtils.isEmpty(content)){
                            eqsEquipment.setMaintenEndDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 25){
                        if(!StringUtils.isEmpty(content)){
                            eqsEquipment.setRejectEndDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 26){
                        eqsEquipment.setDevStatus(content);
                    }else if(i == 27){
                        eqsEquipment.setIsDiscard(content);
                    }else if(i == 28){
                        if(!StringUtils.isEmpty(content)){
                            eqsEquipment.setDiscardDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 29){
                        eqsEquipment.setDiscardType(content);
                    }else if(i == 30){
                        eqsEquipment.setCurrencyKind(content);
                    }else if(i == 31){
                        eqsEquipment.setCostCenter(content);
                    }else if(i == 32){
                        eqsEquipment.setRemarks(content);
                    }else if(i == 33){
                        eqsEquipment.setAssetAttributes(content);
                    }else if(i == 34){
                        eqsEquipment.setIsSpecial(content);
                    }
                }
                eqsEquipments.add(eqsEquipment);
            }
            workbook.close();

        } else {
            return responseResult.error("excel模板有误");
        }

        if(eqsEquipments.size() > 0){
            for(EqsEquipment equipment : eqsEquipments){
                EntityWrapper<EqsEquipment> entityWrapper = new EntityWrapper<>(EqsEquipment.class);
                entityWrapper.eq("code",eqsEquipment.getCode());
                eqsEquipmentService.delete(entityWrapper);
                eqsEquipmentService.insert(equipment);
            }
        }

        return responseResult.ok("操作完成");
    }

    @RequestMapping(value = "importSparePartExcel", method = {RequestMethod.POST, RequestMethod.GET})
    public Response importSparePartExcel(MultipartFile file,HttpServletRequest request, HttpServletResponse response) throws IOException {
        Response responseResult = new Response();
        Workbook workbook = null;
        EqsSparePart eqsSparePart = null;
        InputStream in = file.getInputStream();
        try {
            workbook = Workbook.getWorkbook(in);
        } catch (BiffException e) {

        }
        List<EqsSparePart> eqsSpareParts = new ArrayList<EqsSparePart>();
        Sheet sheet = workbook.getSheet(0);// 选取excel中的第一页
        int rows = sheet.getRows();// 得到此页的行(不要设置状态列的上传否则管理混乱)
        int cols = sheet.getColumns();// 得到此页的列(以实际设定的列数为准)
        for (int row = 1; row < rows; row++) {
            String val1 = sheet.getCell(0, row).getContents();//编码
            String val2 = sheet.getCell(1, row).getContents();//名称
            if (val1.equals("") && val2.equals("")) {
                rows = rows - 1;
            }
        }

        if (rows > 1 && cols == 42) {
            dump:
            for (int j = 2; j < rows; j++) {
                EqsSparePart sparePart = new EqsSparePart();
                for (int i = 0; i < cols; i++) {
                    String content = sheet.getCell(i, j).getContents();
                    if(i == 0){
                        //如果编码为空忽略这一行。
                        if(StringUtils.isEmpty(content)){
                            break dump;
                        }
                        sparePart.setCode(content);
                    }else if(i == 1){
                        sparePart.setName(content);
                    }else if(i == 2){
                        sparePart.setSpareCatalogCode(content);
                    }else if(i == 3){
                        sparePart.setLocationCode(content);
                    }else if(i == 4){
                        sparePart.setQualityCode(content);
                    }else if(i == 5){
                        sparePart.setPrice(new Double(content));
                    }else if(i == 6){
                        sparePart.setImportance(content);
                    }else if(i == 7){
                        if(!StringUtils.isEmpty(content)){
                            sparePart.setMinSafeStock(Integer.parseInt(content));
                        }
                    }else if(i == 8){
                        if(!StringUtils.isEmpty(content)){
                            sparePart.setWarehouseCount(Integer.parseInt(content));
                        }
                    }else if(i == 9){
                        sparePart.setStatus(content);
                    }else if(i == 10){
                        sparePart.setCheckFreq(content);
                    }else if(i == 11){
                        sparePart.setSecCode(content);
                    }else if(i == 12){
                        sparePart.setKindCode(content);
                    }else if(i == 13){
                        sparePart.setBrand(content);
                    }else if(i == 14){
                        sparePart.setModel(content);
                    }else if(i == 15){
                        sparePart.setOtherProp(content);
                    }else if(i == 16){
                        sparePart.setFac(content);
                    }else if(i == 17){
                        sparePart.setAcc(content);
                    }else if(i == 18){
                        if(!StringUtils.isEmpty(content)){
                            sparePart.setStockDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 19){
                        if(!StringUtils.isEmpty(content)){
                            sparePart.setDevDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 20){
                        sparePart.setChargeby(content);
                    }else if(i == 21){
                        sparePart.setDevUseman(content);
                    }else if(i == 22){
                        if(!StringUtils.isEmpty(content)){
                            sparePart.setArDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 23){
                        sparePart.setBuyContract(content);
                    }else if(i == 24){
                        sparePart.setBuyPrs(content);
                    }else if(i == 25){
                        sparePart.setDevUse(content);
                    }else if(i == 26){
                        sparePart.setDevSource(content);
                    }else if(i == 27){
                        sparePart.setTotalfee(content);
                    }else if(i == 28){
                        sparePart.setDepreType(content);
                    }else if(i == 29){
                        sparePart.setSalvageValueRate(content);
                    }else if(i == 30){
                        sparePart.setPreDepreciationMoon(content);
                    }else if(i == 31){
                        if(!StringUtils.isEmpty(content)){
                            sparePart.setMaintenEndDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 32){
                        if(!StringUtils.isEmpty(content)){
                            sparePart.setRejectEndDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 33){
                        sparePart.setDevStatus(content);
                    }else if(i == 34){
                        sparePart.setIsDiscard(content);
                    }else if(i == 35){
                        if(!StringUtils.isEmpty(content)){
                            sparePart.setDiscardDate(TimeUtils.getDateFromTime("yyyy-MM-dd",content));
                        }
                    }else if(i == 36){
                        sparePart.setDiscardType(content);
                    }else if(i == 37){
                        sparePart.setCurrencyKind(content);
                    }else if(i == 38){
                        sparePart.setCostCenter(content);
                    }else if(i == 39){
                        sparePart.setAssetAttributes(content);
                    }else if(i == 40){
                        sparePart.setIsSpecial(content);
                    }else if(i == 41){
                        sparePart.setEquipmentCode(content);
                    }
                }
                eqsSpareParts.add(sparePart);
            }
            workbook.close();

        } else {
            return responseResult.error("excel模板有误");
        }

        if(eqsSpareParts.size() > 0){
            for(EqsSparePart sparePart : eqsSpareParts){
                EntityWrapper<EqsSparePart> entityWrapper = new EntityWrapper<>(EqsSparePart.class);
                entityWrapper.eq("code",sparePart.getCode());
                eqsSparePartService.delete(entityWrapper);
                eqsSparePartService.insert(sparePart);

                EntityWrapper<EqsEquipment> entityWrapper_ = new EntityWrapper<>(EqsEquipment.class);
                entityWrapper_.eq("code",sparePart.getEquipmentCode());
                EqsEquipment eqsEquipment = eqsEquipmentService.selectOne(entityWrapper_);
                EqsEquipmentFixture eqsEquipmentFixture = new EqsEquipmentFixture();
                eqsEquipmentFixture.setFixtureId(sparePart.getId());
                eqsEquipmentFixture.setEquipmentId(eqsEquipment == null ? "":eqsEquipment.getId());
                eqsEquipmentFixtureService.insert(eqsEquipmentFixture);
            }
        }
        return responseResult.ok("操作完成");
    }
}